﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using ZC.MUSIC.DependencyPropertys;

namespace ZC.MUSIC.Views
{
    /// <summary>
    /// WindowInherited.xaml 的交互逻辑
    /// </summary>
    public partial class WindowInherited : Window
    {
        #region 只读依赖属性属性
        private static readonly DependencyPropertyKey counterKey = DependencyProperty.RegisterReadOnly("Counter", typeof(int), typeof(WindowInherited), new PropertyMetadata(0));
        
        /// <summary>
        /// 属性包装器
        /// </summary>
        public int Counter
        {
            get { return (int)GetValue(counterKey.DependencyProperty); }
        }
        #endregion

        private struct FontSizeClass
        {
            public string Name { get; set; }

            public int Value { get; set; }
        }

        private List<FontSizeClass> fontSizes;

        public WindowInherited()
        {
            InitializeComponent();
            //用SetValue的方法来设置值
            DispatcherTimer timer =
                new DispatcherTimer(TimeSpan.FromSeconds(1),
                                    DispatcherPriority.Normal,
                                    (object sender, EventArgs e) =>
                                    {
                                        int newValue = Counter == int.MaxValue ? 0 : Counter + 1;
                                        SetValue(counterKey, newValue);
                                    },
                                    Dispatcher);

        }


        private void btnFontSize_Click(object sender, RoutedEventArgs e)
        {
            SimpleDp1 simpleDp = new SimpleDp1();
            
            simpleDp.ValidDP = 1;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Init();

        }

        private void Init()
        {
            fontSizes = new List<FontSizeClass>();
            fontSizes.Add(new FontSizeClass { Name = "15号", Value = 15 });
            fontSizes.Add(new FontSizeClass { Name = "20号", Value = 20 });
            this.drpWinFontSize.ItemsSource = fontSizes;
        }

        private void drpWinFontSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.FontSize = (int)this.drpWinFontSize.SelectedValue;
        }
    }
}
